#ifndef _EVUTIL_H_
#define _EVUTIL_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <sys/types.h>   
#include <sys/socket.h>
#include <sys/time.h>
#include <stdint.h>
#include <inttypes.h>
#include <sys/types.h>
#include <stdarg.h>
#include <sys/time.h>
#include <stdlib.h>

#define ev_uint64_t uint64_t
#define ev_int64_t int64_t
#define ev_uint32_t unsigned int
#define ev_int32_t int
#define ev_uint16_t uint16_t
#define ev_uint8_t unsigned char


int evutil_socketpair(int d, int type, int protocol, int sv[2]);
int evutil_make_socket_nonblocking(int sock);

#define EVUTIL_CLOSESOCKET(s) close(s)
#define EVUTIL_SOCKET_ERROR() (errno)
#define EVUTIL_SET_SOCKET_ERROR(errcode)		\
		do { errno = (errcode); } while (0)



#define evutil_timeradd(tvp, uvp, vvp) timeradd((tvp), (uvp), (vvp))
#define evutil_timersub(tvp, uvp, vvp) timersub((tvp), (uvp), (vvp))
#define evutil_timerclear(tvp) timerclear(tvp)
#define	evutil_timercmp(tvp, uvp, cmp)							\
	(((tvp)->tv_sec == (uvp)->tv_sec) ?							\
	 ((tvp)->tv_usec cmp (uvp)->tv_usec) :						\
	 ((tvp)->tv_sec cmp (uvp)->tv_sec))
#define evutil_timerisset(tvp) timerisset(tvp)



/* big-int related functions */
ev_int64_t evutil_strtoll(const char *s, char **endptr, int base);
#define evutil_gettimeofday(tv, tz) gettimeofday((tv), (tz))


int evutil_snprintf(char *buf, size_t buflen, const char *format, ...);

int evutil_vsnprintf(char *buf, size_t buflen, const char *format, va_list ap);

#ifdef __cplusplus
}
#endif

#endif /* _EVUTIL_H_ */
